{php include wl_template('common/header');}
<ul class="nav nav-tabs">
    <li class="active"><a href="javascript:;">交易组件申请</a></li>
</ul>
<div class="app-content">
    <div class="channel-set">
        <div class="pull-left">
            <div class="channel-title">自定义交易组件申请</div>
            <div class="channel-des">申请交易组件，打通视频号</div>
        </div>
        <div class="pull-right">
            <a class="btn btn-primary ajaxmodal" href="{php echo web_url('wxchannels/channelsapply/StoreModal')}" >更新商户</a>
            <a class="btn btn-primary" href="javascript:;"  id="updateAccess" >更新令牌</a>
        </div>
    </div>
    <div class="app-form">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form action="" class="form-horizontal form " method="post">
                    <div class="panel-body">
                        {if $AccessInfo['errcode'] > 0}
                        <div class="form-group">
                            <div class="col-sm-2 control-label">开通申请</div>
                            <div class="col-sm-9">
                                <a class="btn btn-primary" href="{php echo web_url('wxchannels/channelsapply/applyAccess')}" data-toggle="ajaxRemove" data-confirm="提交申请后，请小程序管理员注意小程序服务通知内开通确认信息。">点击申请接入</a>
                            </div>
                        </div>
                        {/if}
                        <div class="form-group">
                            <div class="col-sm-2 control-label">组件开通</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" value="{$accessinfo}" readonly="readonly"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">商品接入</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" value="{$goodsAccessinfo}" readonly="readonly"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">订单接口</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" value="{$orderAccessInfo}" readonly="readonly"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">生成接口订单</div>
                            <div class="col-sm-9">
                                <a class="btn btn-primary ajaxmodal" href="{php echo web_url('wxchannels/channelsapply/getOrderQr')}" >点击支付订单</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">物流接口</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" value="{$deliveryAccessInfo}" readonly="readonly"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">售后接口</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" value="{$afterAccessInfo}" readonly="readonly"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">售后接口测试</div>
                            <div class="col-sm-9">
                                <a class="btn btn-primary ajaxmodal" href="{php echo web_url('wxchannels/channelsapply/afterModal')}" >提交售后申请</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">测试接入</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" value="{$textAccessInfo}" readonly="readonly"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2 control-label">小程序发布</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" value="{$wxappAccessInfo}" readonly="readonly"/>
                            </div>
                        </div>

                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    $('#updateAccess').click(function(e){
        e.stopPropagation();
        util.nailConfirm(this, function(state) {
            if(!state) return;
            $('#updateAccess').html('<i class="fa fa-spinner fa-spin"></i>处理中');
            $.post("{php echo web_url('wxchannels/channelsapply/updateAccess')}", {}, function(data){
                util.tips("更新成功！");
                location.reload();
            }, 'json');
        }, {html: "确认更新令牌?"});
    });

    $('.ajaxmodal').click(function(e){
        e.preventDefault();
        var obj = $(this),
            confirm = obj.data("confirm");
        var handler = function () {
                $("#ajaxModal").remove(), e.preventDefault();
                var url = obj.data("href") || obj.attr("href"),
                    data = obj.data("set"),
                    modal;
                $.ajax(url, {
                    type: "get",
                    dataType: "html",
                    cache: false,
                    data: data
                }).done(function (html) {
                    if (html.substr(0, 8) == '{"status') {
                        json = eval("(" + html + ')');
                        if (json.status == 0) {
                            msg = typeof (json.result) == 'object' ? json.result.message : json.result;
                            tip.msgbox.err(msg || tip.lang.err);
                            return
                        }
                    }
                    modal = $('<div class="modal fade" id="ajaxModal"><div class="modal-body "></div></div>');
                    $(document.body).append(modal), modal.modal('show');
                    myrequire(['js/jquery.gcjs'], function () {
                        modal.append2(html, function () {
                            var form_validate = $('form.form-validate', modal);
                            if (form_validate.length > 0) {
                                $("button[type='submit']", modal).length && $("button[type='submit']", modal).attr("disabled", true);
                                myrequire(['js/form'], function (form) {
                                    form.init();
                                    $("button[type='submit']", modal).length && $("button[type='submit']", modal).removeAttr("disabled")
                                })
                            }
                        })
                    })
                })
            },
            a;
        if (confirm) {
            tip.confirm(confirm, handler)
        } else {
            handler()
        }
    });


</script>


{php include wl_template('common/footer');}